function PerlinNoise2d(x, y){
  var total = 0.0;
  
  var frequency   = .015; // USER ADJUSTABLE
  var persistence = .65;  // USER ADJUSTABLE
  var octaves     = 8;    // USER ADJUSTABLE
  var amplitude   = 1;    // USER ADJUSTABLE
  
  //var lcv;
  for(var lcv = 0; lcv < octaves; lcv++)
  {
    total = lcv;
	total = total + Smooth(x * frequency, y * frequency) * amplitude;
    frequency = frequency * 2;
    amplitude = amplitude * persistence;
  }
  
  var cloudCoverage = 0; // USER ADJUSTABLE
  var cloudDensity  = 1; // USER ADJUSTABLE
  
  total = (total + cloudCoverage) * cloudDensity;
  
  //if(total < 0) total = 0.0;
  //if(total > 1) total = 1.0;
  
  return total;
}

function Smooth(x,y)
{
  var n1 = Noise(x, y);
  var n2 = Noise(x + 1, y);
  var n3 = Noise(x, y + 1);
  var n4 = Noise(x + 1, y + 1);
  
  var i1 = Interpolate(n1, n2, 0);
  var i2 = Interpolate(n3, n4, 0);
  
  //return n1;
  return Interpolate(i1, i2, 0);
}

var r1 = Math.random() * (9000)+1000;
var r2 = Math.random() * (900000)+100000
var r3 = Math.random() * (1000000000)+1000000000;

function Noise(x, y)
{
  var n = x + y * 57;
  n = Math.pow((n<<13),n);
  return ( 1.0 - ( (n * (n * n * r1 + r2) + r3) & 0x7fffffff) / 1073741824.0);
}

function Interpolate(x, y, a)
{
  var val = (1 - Math.cos(a * Math.PI)) * .5;
  return  x * (1 - val) + y * val;
}

function helloWorld() {
	var simple = 
			{
				"freq" : PerlinNoise2d(1,1), // C0
				"dur" : 1/4
			}
   var num = Math.round();
   alert(simple.freq);
}